package org.hydrakyoufeng.stuplatform.controller;

import org.hydrakyoufeng.stuplatform.service.QiniuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("qiniu")
public class QiniuController {

    private final QiniuService qiniuService;

    @Autowired
    public QiniuController(QiniuService qiniuService) {
        this.qiniuService = qiniuService;
    }

    @GetMapping("getToken")
    public ResponseEntity getToken() throws Exception {
        return ResponseEntity.ok(qiniuService.getToken());
    }

    @GetMapping("getTokenSecret")
    public ResponseEntity getTokenSecret() throws Exception {
        return ResponseEntity.ok(qiniuService.getTokenSecret());
    }

    /**
     * 获取资源URL
     * @param key
     * @return
     * @throws Exception
     */
    @GetMapping("getSourceURL/{key}")
    public ResponseEntity getSourceURL(@PathVariable String key) throws Exception {
        return ResponseEntity.ok(qiniuService.getSourceURL(key));
    }

}